<template>
  <div class="home">
    <div class="search">
      <el-input class="search_input" placeholder="请输入图书名称" v-model="params.book_name"></el-input>
      <el-input class="search_input" placeholder="请输入图书标准码" v-model="params.book_no"></el-input>
      <el-input class="search_input" placeholder="请输入用户名" v-model="params.user_name"></el-input>
      <el-button type="primary" icon="el-icon-search" @click="load">搜索</el-button>
      <el-button type="warning" icon="el-icon-search" @click="clearSearch">清空</el-button>
    </div>

    <el-table :data="tableData">
      <el-table-column prop="id" label="编号">
      </el-table-column>
      <el-table-column prop="book_name" label="图书名称">
      </el-table-column>
      <el-table-column prop="book_no" label="图书标准码">
      </el-table-column>
      <el-table-column prop="user_huiyuanhao" label="用户会员号">
      </el-table-column>
      <el-table-column prop="user_name" label="用户名">
      </el-table-column>
      <el-table-column prop="user_phone" label="用户联系方式">
      </el-table-column>
      <el-table-column prop="score" label="所用积分">
      </el-table-column>
      <el-table-column prop="status" label="借书状态">
      </el-table-column>
      <el-table-column prop="days" label="借书天数">
      </el-table-column>
      <el-table-column prop="return_date" label="归还日期">
      </el-table-column>
      <el-table-column prop="real_date" label="实际归还日期">
      </el-table-column>
      <el-table-column prop="note" label="过期提醒">
        <template v-slot="scope">
          <el-tag type="success" v-if="scope.row.note === '正常借阅中'">{{ scope.row.note }}</el-tag>
          <el-tag type="primary" v-if="scope.row.note === '即将到期'">{{ scope.row.note }}</el-tag>
          <el-tag type="warning" v-if="scope.row.note === '已到期'">{{ scope.row.note }}</el-tag>
          <el-tag type="danger" v-if="scope.row.note === '已过期'">{{ scope.row.note }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="createtime" label="借出日期">
      </el-table-column>
      <el-table-column prop="updatetime" label="更新时间">
      </el-table-column>
      <el-table-column label="操作" width="200">
        <template v-slot="scope">
          <template>
            <el-popconfirm style="margin-left:10px" title="确定删除吗？" @confirm="del(scope.row.id)">
              <el-button size="mini" type="danger" slot="reference">删除</el-button>
            </el-popconfirm>
          </template>
        </template>
      </el-table-column>
    </el-table>

    <div class="page">
      <el-pagination :page-size="params.pageSize" :current-page="params.pageNum" @current-change="changeCurrentPage"
        background layout="prev, pager, next" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Borrow',
  data() {
    return {
      tableData: [],
      total: 0,
      params: {
        book_name: '',
        book_no: '',
        user_name: '',
        pageNum: 1,
        pageSize: 5,
      }
    }
  },
  created() {
    this.load();
  },
  methods: {
    load() {
      this.request.get("/api/borrow/retur/page", { params: this.params }).then(res => {
        if (res.code === '200') {
          this.tableData = res.data.list;
          console.log(this.tableData)
          this.total = res.data.total;
        }
      })
    },
    changeCurrentPage(index) {
      this.params.pageNum = index;
      this.load();
    },
    del(id) {
      this.request.delete("/api/borrow/retur/delete/" + id).then(res => {
        if (res.code === '200') {
          this.$notify.success("删除成功");
          this.params.pageNum = 1;
          this.load();
        }
      })
    },
    clearSearch() {
      this.params = {};
    }
  }
}
</script>


<style lang="scss" scoped>
.home {
  .search {
    display: flex;
    margin: 10px 0;

    .search_input {
      width: 20%;
      margin-right: 10px;
    }
  }

  .page {
    display: flex;
    justify-content: center;
    margin: 20px 0;
  }
}
</style>